const jwt = require('jsonwebtoken')

const { PRIVATE_kEY, PUBLIC_kEY } = require('../app/config')

class AuthController {
  async login(ctx, next) {
    const { id, name } = ctx.user
    // 颁发令牌
    const token = jwt.sign({ id, name }, PRIVATE_kEY, {
      expiresIn: 60 * 60 * 24,
      algorithm: 'RS256'
    })
    ctx.body = { id, name, token }
  }
  async success(ctx, next) {
    ctx.body = ctx.user
  }
}

module.exports = new AuthController()